package com.mask.sca.system.service.impl;

import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.mask.sca.system.entity.User;
import com.mask.sca.system.mapper.UserMapper;
import com.mask.sca.system.service.UserQueryService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.mask.sca.system.vo.UserRoleVO;
import com.mask.sca.system.entity.Role;

import java.util.List;

@Service
public class UserQueryServiceImpl implements UserQueryService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public User findById(Long id) {
        return userMapper.selectById(id);
    }

    @Override
    public User findByUsernameAndTenantId(String username, String tenantId) {
        return null;
    }

    @Override
    public List<User> findAll() {
        return userMapper.selectList(null);
    }

    @Override
    public IPage<User> findPage(int page, int size) {
        Page<User> pageObj = new Page<>(page, size);
        return userMapper.selectPage(pageObj, null);
    }

    @Override
    public List<UserRoleVO> getUserWithRoles() {
        return userMapper.selectJoinList(UserRoleVO.class,
            new MPJLambdaWrapper<User>()
                .selectAll(User.class)
                .leftJoin(Role.class, Role::getId, User::getId)
        );
    }
} 